import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

plt.rcParams['font.sans-serif'] = ['STHeiti', 'PingFang SC', 'Heiti TC', 'Microsoft YaHei', 'SimHei', 'Arial Unicode MS']  
plt.rcParams['axes.unicode_minus'] = False

# 读取为DataFrame
df = pd.read_csv("data-6.csv", header=0, index_col=0)

# 提取x轴
x = [0, 4, 8, 12, 16, 20]

# 获取所有的年份
years = ['2025', '2030', '2035', '2040', '2045', '2050']

# 统一索引名的小写处理
df.index = df.index.str.lower()

fig, axes = plt.subplots(2, 3, figsize=(10, 6), sharex=True, sharey=True)
axes = axes.flatten()
axes[0].set_ylabel('火电机组日平均出力曲(mw)')
axes[3].set_ylabel('火电机组日平均出力曲线(mw)')
for i, year in enumerate(years):
    ax = axes[i]
    fix = df.loc[f'output-china{year}fix']
    v1g = df.loc[f'output-china{year}v1g']
    v2g = df.loc[f'output-china{year}v2g']
    
    ax.plot(x, fix, label='随到随充', marker='o')
    ax.plot(x, v1g, label='有序充电', marker='s')
    ax.plot(x, v2g, label='车网互动', marker='^')
    ax.set_title(str(year))
    ax.set_xticks(x)
    ax.set_xlabel('Time')
    
    # ax.grid(True)
    # ax.legend()
    
fig.legend(['随到随充', '有序充电', '车网互动'], loc='upper center', ncol=3, bbox_to_anchor=(0.5, 1))

# rect=[left, bottom, right, top]
# left=0：布局从画布最左边开始
# bottom=0：布局从画布最底下开始
# right=1：布局到画布最右边结束
# top=0.95：布局不要占满顶部，最多到 95% 高度
plt.tight_layout(rect=[0, 0, 1, 0.95])  # 留出顶部空间

plt.savefig("6.jpg")